#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .. import command
from utility.odoo_manager import OdooManager

"""获取高危因素"""
def get_gwys_value(gwys):
    results = []
    try:
        odoo = OdooManager().get_instance()
        for gwys_ in gwys:
            query_ = [('id', '=', int(gwys_))] 
            value_ = odoo.env['dict.gwys'].search_read(query_)
            if value_:
                value_ = value_[0]
                #上级信息
                query_p = [('id', '=', int(value_['parent_id']))] 
                value_p = odoo.env['dict.gwys'].search_read(query_p)
                query_p = [('id', '=', int(value_['color']))] 
                value_c = odoo.env['dict.dictionary'].search_read(query_p)
                data_ = {
                    'gwysflCode': value_p[0]['code'] if value_p else '',
                    'gwysflName': value_p[0]['name'] if value_p else '',
                    'gwysBm': value_['code'],
                    'gwysMc': value_['name'],
                    'gwColor':value_c[0]['key'] if value_c else '',
                    'gwColorCode':value_c[0]['value'] if value_c else '',
                }
                results.append(data_)
    except Exception as e:
        print (e)  
    return results

